﻿using System;
using System.Reflection;
using System.Text;
using Furion;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Xwltz.Net.Tools.Helper;
using Xwltz.Net.Tools.Model;

namespace Xwltz.Net.Tools
{
    public class GlobalContext
    {
        #region 公开属性、方法

        public static IWebHostEnvironment HostingEnvironment => App.WebHostEnvironment;

        public static string GetVersion()
        {
            Version version = Assembly.GetEntryAssembly()?.GetName().Version;
            if (version is not null) return version.Major + "." + version.Minor;
            return string.Empty;
        }

        /// <summary>
        /// 程序启动时，记录目录
        /// </summary>
        /// <param name="env"></param>
        public static void LogWhenStart(IWebHostEnvironment env)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("程序启动");
            sb.Append(" |ContentRootPath:" + env.ContentRootPath);
            sb.Append(" |WebRootPath:" + env.WebRootPath);
            sb.Append(" |IsDevelopment:" + env.IsDevelopment());
            LogHelper.Debug(sb.ToString());
        }

        /// <summary>
        /// 获取系统配置
        /// </summary>
        public static SystemConfig SystemConfig => App.GetOptions<SystemConfig>();

        #endregion

    }
}